/** Header file for planet destruction
*	Created 17.9.2009 by Raymond; common.h massacre
*	*/
#ifndef PLAYER_H
#define PLAYER_H

#include <vector>
#include "port.h"

#include "common.h"
#include "databank.h"
#include "weapon.h"
#include "interface.h"

using namespace std;

enum TurnStatus {
	TURN_FINISHED,
	TURN_UNFINISHED
};

class Gravitated;

/** Class that stores information about a given player */
class Player {

    DataBank *myDatabank;
	double position[2]; // Center of player
	int id;
	vector<Weapon *> weapons;
	Weapon *cweapon;
	double direction; // In binary angle [0..256]
	bool direction_update;
	double power;
	PlayerType type;
	bool flagLeft;
	bool flagRight;
	bool flagFire;
	bool flagUp;
	bool flagDown;
	bool flagNext;
	bool flagDead;
    int hp;
    int color;
    int magicPink;
    	Interface intf;
	
	BITMAP *plbmp;
	BITMAP *rotated;
public:
	void input();
	TurnStatus process(double delta);
	bool testCollision(double *pos);
	void updateBitmap();
	BITMAP *getBitmap() { return rotated; }
	
    Player(DataBank *_myDatabank) {
        myDatabank = _myDatabank;
        flagLeft = false;
        flagRight = false;
        flagFire = false;
        flagUp = false;
        flagDown = false;
        flagNext = false;
        flagDead = false;
        direction_update = true;
        
        cweapon = NULL;
        rotated = NULL;
        
        power = 7000.0;
        
        magicPink = makecol(255,0,255);
    }
    
    void setup();
    
    void giveWeapon(Weapon *w) { weapons.push_back(w); }
    std::vector<Weapon *> *getWeapons() { return &weapons; }
    Weapon *curWeapon() { return cweapon; }

	void setType(PlayerType type) {
        this->type = type;
    }
    
    void setColor(int color) { this->color = color; }

    PlayerType getType(void) {
        return type;
    }

    void setPos(double x, double y) {
        position[0] = x;
        position[1] = y;
    }

    double* getPos(void) {
        return position;
    }

    void setDir(double dir) {
        direction = dir;
    }

    double getDir(void) {
        return direction;
    }
    
    void setPower(double p) { power = p; }
    double getPower(void) { return power; }
    Interface *getInterface(void) { return (&intf); }

    void setID(int id) {
        this->id = id;
    }

    int getID(void) {
        return id;
    }

    void setHP(int hp) {
        this->hp = hp;
    }
    
    void damage(int dmg) { this->hp -= dmg; }
    void die(DataBank *d);
    bool alive(void) { return ( (hp > 0) ? true : false ); }
    void testDead(DataBank *b);

    int getHP(void) {
        return hp;
    }
};

#endif
